package com.example.controller;

import com.example.common.Page;
import com.example.common.PageQueryParam;
import com.example.entity.TUserEntity;
import com.example.service.TUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

@RestController
@RequestMapping("/tuser")
public class TUserController {

    @Autowired
    private HttpServletRequest request;

    @Autowired
    private HttpServletResponse response;

    @Autowired
    private TUserService tUserService;

    @RequestMapping(value = "/query", method = RequestMethod.GET)
    public List<TUserEntity> query(){
        return tUserService.selectAll();
    }

    @RequestMapping(value = "/login", method = RequestMethod.POST)
    public Integer loginChecking(@RequestBody(required = false) TUserEntity user){
        Integer integer = tUserService.loginChecking(user, response);

        return integer;
    }

    @RequestMapping(value = "/query",method = RequestMethod.POST)
    public Page<TUserEntity> queryPage(@RequestBody(required = false)PageQueryParam<TUserEntity> pageQueryParam){
        return tUserService.queryPage(pageQueryParam);
    }

    @RequestMapping(value = "/delete",method = RequestMethod.POST)
    public void delete(Integer id){
        tUserService.delete(id);
    }

    @RequestMapping(value = "/create",method = RequestMethod.POST)
    public void create(@RequestBody(required = true)TUserEntity userEntity){
        tUserService.create(userEntity);
    }

}
